import wx
import wx.lib.buttons as buttons

# wx.SetTranslation(wx.LANGUAGE_ENGLISH) # 声明为英文环境
# print(wx.GetTranslation())

string_temp = """\
import wx

class MainFrameGUI(wx.Frame):
    def __init__(self, parent = None):
        wx.Frame.__init__(self, parent, id = wx.ID_ANY, title = '程序名称', pos = wx.DefaultPosition, size = wx.Size(300, 160), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL)
        self.panel = wx.Panel(self)
        self.panelSizer = wx.BoxSizer(wx.VERTICAL)
        self.panel.SetSizer(self.panelSizer)
        self.panel.SetBackgroundColour('#0000ff')

class App(wx.App):
    def __init__(self, redirect=False, filename=None, useBestVisual=False, clearSigInt=True):
        wx.App.__init__(self, redirect, filename, useBestVisual, clearSigInt)

    def OnInit(self):
        self.frame = MainFrameGUI()
        self.frame.SetWindowStyle(wx.DEFAULT_FRAME_STYLE)
        self.frame.Show(True)
        self.SetTopWindow(self.frame)
        return True

    def OnExit(self):
        return super().OnExit()

if __name__ == '__main__':
    app = App(redirect=False)
    app.MainLoop()

"""

class MainFrameGUI(wx.Frame):
    def __init__(self, parent = None):
        wx.Frame.__init__(self, parent, id = wx.ID_ANY, title = '本程序wxPython文档格式转换器', pos = wx.DefaultPosition, size = wx.Size(1200, 600), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL)
        self.panel = wx.Panel(self)
        self.panelSizer = wx.BoxSizer(wx.VERTICAL)
        self.panel.SetSizer(self.panelSizer)
        
        '''
            顶部工具栏
        '''
        self.topPanel = wx.Panel(self.panel)
        topPanelSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.topPanel.SetSizer(topPanelSizer)
        self.panelSizer.Add(self.topPanel, 0, wx.EXPAND | wx.ALL, 2)

        self.convert = buttons.GenButton(self.topPanel, -1, label='转换')
        self.fconvert = buttons.GenButton(self.topPanel, -1, label='反向转换')
        topPanelSizer.Add(self.convert, 0, wx.EXPAND | wx.ALL, 2)
        topPanelSizer.Add(self.fconvert, 0, wx.EXPAND | wx.ALL, 2)

        self.Bind(wx.EVT_BUTTON, self.onConvert, self.convert)
        self.Bind(wx.EVT_BUTTON, self.onFConvert, self.fconvert)

        '''
            内容展示栏
        '''
        self.contentPanel = wx.Panel(self.panel)
        contentPanelSizer = wx.BoxSizer(wx.HORIZONTAL)
        self.contentPanel.SetSizer(contentPanelSizer)
        self.panelSizer.Add(self.contentPanel, 1, wx.EXPAND | wx.ALL, 2)

        self.leftContent = wx.TextCtrl(self.contentPanel, -1, style=wx.TE_MULTILINE|wx.TE_RICH)
        self.rightContent = wx.TextCtrl(self.contentPanel, -1, style=wx.TE_MULTILINE|wx.TE_RICH)
        contentPanelSizer.Add(self.leftContent, 1, wx.EXPAND | wx.ALL, 2)
        contentPanelSizer.Add(self.rightContent, 1, wx.EXPAND | wx.ALL, 2)

        self.leftContent.SetValue(string_temp)

    def onConvert(self, e):
        """内容转换"""
        temp_content: str = str(self.leftContent.GetValue())
        out_str = ''
        for _ in temp_content.split("\n"):
            out_str += f'"{_}",\n'

        self.rightContent.SetValue(out_str)

    def onFConvert(self, e):
        """内容反向转换"""
        temp_content: str = str(self.rightContent.GetValue())
        
        self.leftContent.SetValue('\n'.join([_.strip().strip(',"') for _ in temp_content.split('\n')]))

class App(wx.App):
    def __init__(self, redirect=False, filename=None, useBestVisual=False, clearSigInt=True):
        wx.App.__init__(self, redirect, filename, useBestVisual, clearSigInt)

    def OnInit(self):
        self.frame = MainFrameGUI()
        self.frame.SetWindowStyle(wx.DEFAULT_FRAME_STYLE)
        self.frame.Show(True)
        self.SetTopWindow(self.frame)
        return True

    def OnExit(self):
        return super().OnExit()

if __name__ == '__main__':
    app = App(redirect=False)
    app.MainLoop()
